new Vue({
    el: '#app',
    data() {
        return {
            form: {
                Role_SerialNumber: '',
                Role_Name: '',//表名
                Role_Describe: '',//描述
            },
            rules: {
                Role_Name: [{ required: true, message: '请输入角色名称', trigger: 'blur' }],
            },
            loading: false,
        }
    },
    mounted() {
        const Role_SerialNumber = sessionStorage.getItem("Role_SerialNumber")
        this.getData(Role_SerialNumber);
    },
    methods: {
        getData(Role_SerialNumber) {
            const that = this;
            $.ajax({
                headers:requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                type: 'POST',
                data: { 
                    Data: "base_system_role_info" ,
                    Condition: "Role_SerialNumber = '"+Role_SerialNumber+"'"
                },
                success: function (Result) {
                    if (Result.length == 1) {
                        that.form = configOriginal(Result[0])
                    }
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        submitForm(formName) {
            const that = this
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    that.loading = true;
                    $.ajax({
                        headers:requestHeaders(),
                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                        type: 'POST',
                        data: {
                            Data: JSON.stringify({ 
                                Modify: { base_system_role_info: [that.form] } ,
                                Add:{base_operation_log:[generateLog('修改角色', '平台端操作', 'base_system_role_info', JSON.stringify({ Modify: { base_system_role_info: [that.form] } }))]}
                            })
                        },
                        success: function (res) {
                            if (res.Status === 'success') {
                                that.$message.success("提交成功")
                                window.history.go(-1)
                            } else {
                                that.$message.error("提交失败，请稍后再试")
                            }
                        },
                        complete: function (XMLHttpRequest) {
                            that.loading = false
                            requestPretreatment(XMLHttpRequest);
                        },
                        dataType: "json"
                    })
                } else {
                    that.$message({
                        message: sumberError,
                        type: 'warning'
                    })
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
    }
})